<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>进行foreach遍历</title>
</head>
<!-- 定义数组 -->
<?php
$arr=[['auname'=>'张三','id'=>'1','mon'=>12],
['auname'=>'历史','id'=>'2','mon'=>22],
['auname'=>'阿布','id'=>'3','mon'=>32]];
// 搜索

if(!empty($_POST['name'])){
    $autername=$_POST['name'];
    $arr=array_filter($arr,function($v) use ($autername){
      return $v['auname']==$autername;
    });
}

if(!empty($_POST['txtprice'])){
   $price=$_POST['txtprice'];
   $arr=array_filter($arr,function($v) use ($price){
    return $v['mon']==$price;
  });
}
?>
<body>
    <!-- 搜索框 -->
    <form action="" method='post'> 
        <input type="text" name='name'>
        <input type="submit" name='btn' value="查询书名">
    </form>
    <form action="" method='post'> 
        <input type="text" name='txtprice'>
        <input type="submit" name='btn' value="查询价格">
    </form>
    <!-- 显示 -->
    <table border="1" cellspacing="0" >
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>价格</th>
        </tr>
       <?php foreach ($arr as $value){?>
           <tr>
           <td><?php echo $value['id']?></td>
           <td><?php echo $value['auname']?></td>
           <td><?php echo $value['mon']?></td>
           </tr> 
       <?php } ?>
    </table>
</body>
<!-- 搜索 -->

</html>